package com.leo;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @ClassName FxApplication
 * @Description
 * @Author wangss
 * @date 2020.06.24 00:08
 * @Version 1.0
 */
public class FxApplication extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        Locale locale = Locale.getDefault();
        System.out.println(locale.getLanguage());
        System.out.println(locale.getCountry());

//        Locale.setDefault(new Locale("en", "us"));

        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("view/sample.fxml"));
        // 这里根据系统语言会自动获取对应的properties文件
        ResourceBundle rb = ResourceBundle.getBundle("language");
        fxmlLoader.setResources(rb);

        /*Enumeration<String> keys = rb.getKeys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            String value = new String(rb.getString(key).getBytes("ISO-8859-1"), "UTF-8");
            System.out.println(key + "=" + value);
        }*/

        Parent root = fxmlLoader.load();

        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.setWidth(800d);
        primaryStage.setHeight(800d);
        primaryStage.setTitle("国际化");
        primaryStage.show();
    }
}
